package com.nervenets.shopping.controller.verify;

import com.nervenets.general.entity.ResponseResult;
import com.nervenets.general.jwt.aspect.JwtRole;
import com.nervenets.general.jwt.aspect.JwtSecurity;
import com.nervenets.general.web.BaseController;
import com.nervenets.general.web.params.BoolIdParams;
import com.nervenets.shopping.enumeration.CheckStatus;
import com.nervenets.shopping.service.IdCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(value = "审核身份证接口v1", tags = "审核身份证接口")
@RestController
@RequestMapping("/api/verify/id")
//@JwtRole(group = "verify", groupName = "审核管理", function = "id", functionName = "身份证审核", queue = 90)
public class VerifyIdCardController extends BaseController {
    @Resource
    private IdCardService idCardService;

    @ApiOperation(value = "身份证审核")
    @PostMapping
    @JwtSecurity(permission = "check", permissionName = "身份证审核")
    public ResponseEntity<ResponseResult<Void>> check(@Valid @RequestBody BoolIdParams params) {
        idCardService.findById(params.getTargetId()).ifPresent(idCard -> {
            idCard.setCheckStatus(params.isYes() ? CheckStatus.success : CheckStatus.failed);
            idCardService.save(idCard);
        });
        return successMessage();
    }
}
